import requests

# 设置目标URL
base_url = "http://10.160.60.60:5001"
username = "yx2207A-yuanyuzhou"
password = "yx2207A-yuanyuzhou"

try:
    # 创建会话对象来维持登录状态
    session = requests.Session()
    
    # 设置请求头
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
        'Content-Type': 'application/json',
        'Accept': 'application/json, text/plain, */*'
    }
    
    # 尝试访问网站并打印响应内容
    response = session.get(base_url, headers=headers)
    print("初始访问响应：", response.text)
    
    # 修改登录数据格式
    login_data = {
        'userName': username,  # 尝试不同的键名
        'passWord': password,  # 尝试不同的键名
        'remember': True
    }
    
    # 发送登录请求并打印详细信息
    login_response = session.post(
        f"{base_url}/login", 
        json=login_data,  # 使用json参数而不是data
        headers=headers
    )
    
    print(f"登录响应状态码：{login_response.status_code}")
    print(f"登录响应内容：{login_response.text}")
    
    if login_response.status_code == 200:
        print("登录成功！")
    else:
        print(f"登录失败，状态码：{login_response.status_code}")
        
except requests.exceptions.ConnectionError:
    print("连接失败，请检查网址是否正确或网络是否正常")
except Exception as e:
    print(f"发生错误：{str(e)}")